package com.taoyibao.hongcanting.ui.home.views;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.BaseRelativeLayout;
import com.taoyibao.hongcanting.model.DishModel;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.GlideUtil;

/**
 * @author TangAnna
 * @description: 特色菜品item  设置数据模块
 * @date :${DATA} 14:39
 */
public class ItemFeaturesArea extends BaseRelativeLayout<DishModel> {
    /**
     * 菜品缩略图
     */
    private ImageView mIvBg;
    /**
     * 菜品名称
     */
    private TextView mTvName;
    /**
     * 菜品价格
     */
    private TextView mTvPrice;


    public ItemFeaturesArea(Context context) {
        super(context);
    }

    public ItemFeaturesArea(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemFeaturesArea(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initView(Context context, AttributeSet attrs, int defStyleAttr) {
        mIvBg = findViewById(R.id.iv_item_recommend_bg);
        mTvName = findViewById(R.id.tv_item_recommend_name);
        mTvPrice = findViewById(R.id.tv_item_recommend_price);
    }

    @Override
    public void setData(DishModel data) {
        //图片
//        if (!TextUtils.isEmpty(data.dish_pic)) {
//            GlideUtil.getInstance().showDefaultImg(getContext(), data.dish_pic, mIvBg);
//        }
        GlideUtil.getInstance().loadDefaultImage(getContext(), data.dish_pic, mIvBg);
        //名称
        if (!TextUtils.isEmpty(data.dish_name)) {
            mTvName.setText(data.dish_name);
        }
        //价格
        mTvPrice.setText(CodeUtils.formatAmountUnit(data.dish_discount_price) +"/"+data.dish_unit);
    }

    @Override
    protected int bindLayout() {
        return R.layout.item_features;
    }
}
